/****************************************************
 * 创建人：  @author hechengcheng
 * 创建时间: 2019-6-8/16:19:52
 * 项目名称: dfas-common-util
 * 文件名称: WinResponseData.java
 * 文件描述: @Description
 * 公司名称: 深圳市赢时胜信息技术有限公司
 *
 * All rights Reserved, Designed By 深圳市赢时胜信息技术有限公司
 * @Copyright:2019-2030
 *
 ********************************************************/
package com.springboot.win;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 *
 * 包名称： com.dfas.common.vo
 * 类名称：WinResponseData
 * 类描述：返回响应结果
 * 创建人：@author hechengcheng
 * 创建时间：2019年6月8日/下午4:19:48
 *
 */
@Data
@ApiModel(value = "WinResponseData", description = "公用返回对象WinResponseData")
public class WinResponseData<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	private static final String OPERATION_SUCC = "操作成功";

	public enum WinRspType {
		// 返回类型
		SUCC("SUCC", "成功"),
		WARN("WARN", "警告"),
		ERROR("ERROR", "服务器错误, 请联系系统管理员"),
		AUTH_ERROR("AUTH_ERROR", "鉴权失败"),
		UNIQUE("UNIQUE", "唯一性");

		private String key;
		private String value;

		WinRspType(String winRspKey, String value) {
			this.key = winRspKey;
			this.value = value;
		}

		public String getKey() {
			return key;
		}

		public String getValue() {
			return value;
		}
	}

	@ApiModelProperty(value = "返回状态码(根据不同状态码处理不同业务结果)")
	private String code;

	@ApiModelProperty(value = "返回信息")
	private String msg;

	@ApiModelProperty(value = "返回类型")
	private WinRspType winRspType;

	@ApiModelProperty(value = "返回数据")
	private transient T data;

	private WinResponseData() {

	}

	private WinResponseData(WinRspType winRspType) {
		this.winRspType = winRspType;
	}


	private WinResponseData(WinRspType winRspType, String msg) {
		this.winRspType = winRspType;
		this.msg = msg;
	}

	private WinResponseData(WinRspType winRspType, String msg, T data) {
		this.winRspType = winRspType;
		this.msg = msg;
		this.data = data;
	}
	
	private WinResponseData(WinRspType winRspType, String code, String msg, T data) {
		this.winRspType = winRspType;
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	private WinResponseData(String code, T data) {
		this.code = code;
		this.data = data;
	}

	/**
	 * 
	 * @Title: handleSuccess
	 * @Description: 返回成功消息
	 * @param successMsg 消息
	 * @param data 数据
	 * @return   
	 * @return: WinResponseData<T>   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:21:19
	 */
	public static <T> WinResponseData<T> handleSuccess(String successMsg, T data) {
		return new WinResponseData<T>(WinRspType.SUCC, "200", successMsg, data);
	}

	/**
	 * 
	 * @Title: handleSuccess
	 * @Description: 返回成功消息
	 * @param successMsg 消息
	 * @return   
	 * @return: WinResponseData<T>   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:24:21
	 */
	public static <T> WinResponseData<T> handleSuccess(String successMsg) {
		return new WinResponseData<T>(WinRspType.SUCC, "200", successMsg, null);
	}

	/**
	 * 
	 * @Title: handleSuccess
	 * @Description: 返回成功消息
	 * @param data 数据
	 * @return   
	 * @return: WinResponseData<T>   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:24:49
	 */
	public static <T> WinResponseData<T> handleSuccess(T data) {
		return new WinResponseData<T>(WinRspType.SUCC, "200", OPERATION_SUCC, data);
	}
	
	/**
	 * 
	 * @Title: handleWarn
	 * @Description: 返回警告消息
	 * @param warnMsg 消息内容
	 * @return   
	 * @return: WinResponseData<T>   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:25:24
	 */
	public static <T> WinResponseData<T> handleWarn(String warnMsg) {
		return new WinResponseData<T>(WinRspType.WARN, warnMsg);
	}

	/**handleWarn
	 * 
	 * @Title: handleWarn
	 * @Description: 返回警告消息
	 * @param warnMsg 消息内容
	 * @param data 数据
	 * @return   
	 * @return: WinResponseData   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:26:01
	 */
	public static <T> WinResponseData<T> handleWarn(String warnMsg, T data) {
		return new WinResponseData<T>(WinRspType.WARN, warnMsg, data);
	}
	

	/**
	 * 
	 * @Title: handleError
	 * @Description: 返回错误消息
	 * @param code 错误代码
	 * @param errorMsg 消息内容
	 * @return   
	 * @return: WinResponseData   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:26:55
	 */
	public static <T> WinResponseData<T> handleError(String code, String errorMsg) {
		return new WinResponseData<T>(WinRspType.ERROR, code, errorMsg, null);
	}
	
	/**
	 * 
	 * @Title: handleError
	 * @Description: 返回错误消息
	 * @param code 错误代码
	 * @param errorMsg 消息内容
	 * @param data
	 * @return   
	 * @return: WinResponseData   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:27:28
	 */
	public static <T> WinResponseData<T> handleError(String code, String errorMsg, T data) {
		return new WinResponseData<T>(WinRspType.ERROR, code, errorMsg, data);
	}

	/**
	 * 
	 * @Title: handleError
	 * @Description: 返回错误消息
	 * @param errorMsg 消息内容
	 * @param data 数据
	 * @return   
	 * @return: WinResponseData   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:28:47
	 */
	public static <T> WinResponseData<T> handleError(String errorMsg, T data) {
		return new WinResponseData<T>(WinRspType.ERROR, errorMsg, data);
	}

	/**
	 * 
	 * @Title: handleError
	 * @Description: 返回错误消息
	 * @param errorMsg
	 * @return   
	 * @return: WinResponseData   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:29:47
	 */
	public static <T> WinResponseData<T> handleError(String errorMsg) {
		return new WinResponseData<T>(WinRspType.ERROR, errorMsg, null);
	}


	/**
	 * 
	 * @Title: handleError
	 * @Description: 返回错误消息
	 * @return   
	 * @return: WinResponseData   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:30:12
	 */
	public static <T> WinResponseData<T> handleError() {
		return new WinResponseData<T>(WinRspType.ERROR, WinRspType.ERROR.value, null);
	}

	/**
	 * 
	 * @Title: handleAuth
	 * @Description: 返回鉴权错误消息
	 * @param authMsg
	 * @return   
	 * @return: WinResponseData<T>   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:30:46
	 */
	public static <T> WinResponseData<T> handleAuth(String authMsg) {
		return new WinResponseData<T>(WinRspType.AUTH_ERROR, authMsg, null);
	}


	/**
	 * 
	 * @Title: handleUnique
	 * @Description: 返回唯一性消息
	 * @param msg 消息
	 * @return   
	 * @return: WinResponseData   
	 * @throws
	 * @author: hechengcheng 
	 * @Date:  2019年12月12日/下午2:31:12
	 */
	public static <T> WinResponseData<T> handleUnique(String msg) {
		return new WinResponseData<T>(WinRspType.UNIQUE, msg);
	}

    @Override
    public String toString() {
        return "WinResponseData [code=" + code + ", msg=" + msg + ", winRspType=" + winRspType + ", data=" + data + "]";
    }

}
